Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-component-tree

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-component-tree

Serialize and reproduce the state of an entire tree of React components

  • 2.0.0-beta.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-25%
Maintainers
2
Weekly downloads
 
Created
Source

react-component-tree

Serialize and reproduce the state of an entire tree of React components.

Deprecated: React Cosmos is moving towards separating props from state inside fixtures, which means we'll no longer need a combined method for rendering with state. In the next iteration we'll extract recursive state injection & serialization from this package and dump the rest.

A few examples where this can be useful:

  • Using fixtures to load and test components in multiple supported states
  • Extracting the app state when an error occurs in the page and reproducing that exact state later on when debugging
  • "Pausing" the app state and resuming it later (nice for games)

.serialize

Generate a snapshot with the props and state of a component combined, including the state of all nested child components.

var ComponentTree = require('react-component-tree');

myCompany.setProps({public: true});
myCompany.setState({profitable: true});
myCompany.refs.employee54.setState({bored: false});

var snapshot = ComponentTree.serialize(myCompany);

The snapshot looks like this:

{
  public: true,
  state: {
    profitable: true,
    children: {
      employee54: {
        bored: false
      }
    }
  },
}

.render

Render a component and reproduce a state snapshot by recursively injecting the nested state into the component tree it generates.

var myOtherCompany = ComponentTree.render({
  component: CompanyClass,
  snapshot: snapshot,
  container: document.getElementById('content')
});

console.log(myOtherCompany.props.public); // returns true
console.log(myOtherCompany.state.profitable); // returns true
console.log(myOtherCompany.refs.employee54.state.bored); // returns false

FAQs

Package last updated on 19 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc